﻿// owner 蒋家伟

#pragma once
// std
#include <ctime>

// qt
#include <QTimer>
#include <QTime>

// jsdk
#include "ITask.h"
#include "TaskId.h"
#include "ITaskDescription.h"

namespace jsdk
{
    // 所有任务的基类
    class Task : public ITask
    {
    public:
        virtual ~Task() {}
        static OwnerPtr<ITask> create(OwnerPtr<ITaskDescription> opTaskDescription, uint32_t delayTime);

    private:
        virtual const ITaskDescription* getTaskDescription() const override;
        virtual const TaskId& getGroupId() const override;
        virtual bool isInGroup() const override;
        virtual const TaskId& getTaskId() const override;
        virtual void setTaskId(const TaskId& taskId) override;
        virtual void setTaskGroupId(const TaskId& taskGroupId) override;
        virtual bool exctue() override;
        virtual bool hasDelayTime() const;
        virtual void startTimer() const;
        virtual uint32_t getDelayTime() const override { return m_delayTime; };
        virtual void setDelayTime(uint32_t delayTime) { m_delayTime = delayTime; };


        Task(OwnerPtr<ITaskDescription> opTaskDescription, uint32_t delayTime);
    private:
        TaskId m_TaskId                                             = TaskId::s_InvalidTaskId;
        TaskId m_TaskGroupId                                        = TaskId::s_InvalidTaskId;
        OwnerPtr<ITaskDescription> m_opTaskDescription       = nullptr;
        QTimer m_timer;
        uint32_t m_delayTime                                        = 0;
        QTime m_time;
    };
}